; contains wrapper functions for misc assembly functions

global cli
global sti
global outb
global inb
global get_arg
global load_IDT
global flush_gdt
global asm_proc_switch

asm_proc_switch:
	mov eax, [esp + 8]
        mov [eax], ebx
        mov [eax + 4], esi
        mov [eax + 8], edi	
	mov [eax + 12], esp	
	mov [eax + 16], ebp
				;	pushf
				;	mov ebx, [esp]
				;	mov [eax +20], ebx
				;	popf
	mov ecx, [esp]
	mov [eax + 24], ecx
	;; second half
	mov eax, [esp + 4]
        mov ebx, [eax]
        mov esi, [eax + 4]
        mov edi, [eax + 8]
	mov esp, [eax + 12]
	mov ebp, [eax + 16]
				;	mov ebx, [eax + 20]
				;	push ebx
				;	popf
        mov ecx, [eax + 24]
	mov [esp], ecx
        ret
	
; reloads gdtr with a gdtr defined in kernel space
flush_gdt:
	mov ecx, [esp+4]
	xor eax, eax
	mov eax, 0x10
	mov ds, ax
	mov es, ax
	mov ss, ax
	mov gs, ax
	mov fs, ax
	lgdt [ecx]
	jmp 0x08:(.jmp_point)
.jmp_point:
	ret

	
load_IDT:
	mov eax, [esp+4]
	lidt [eax]
	ret

get_arg:
	mov ecx, [esp +4]
	mov eax, [esp + eax*4 + 36]
	ret
	
cli:
	cli
	ret

sti:
	sti
	ret

outb:
	mov eax, [esp+8]
	mov edx, [esp+4]
	out dx, al
	ret

inb:
	mov edx, [esp+4]
	in al, dx
	and eax, 0x000000ff
	ret

